package com.sl.biz.modular.process.dao.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sl.biz.modular.process.dao.domain.dto.ProcessCompDTO;
import com.sl.biz.modular.process.dao.domain.entity.ProcessCompDO;
import com.sl.biz.modular.process.dao.mapper.ProcessCompMapper;
import com.sl.biz.modular.process.dao.service.ProcessCompDaoService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class ProcessCompDaoServiceImpl extends ServiceImpl<ProcessCompMapper, ProcessCompDO> implements ProcessCompDaoService {
    @Override
    public List<ProcessCompDTO> queryList(ProcessCompDO processComp) {
        LambdaQueryWrapper<ProcessCompDO> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(StrUtil.isNotBlank(processComp.getGroupCode()), ProcessCompDO::getGroupCode, processComp.getGroupCode());
        List<ProcessCompDO> list = baseMapper.selectList(wrapper);
        return BeanUtil.copyToList(list, ProcessCompDTO.class);
    }

    @Override
    public Boolean add(ProcessCompDO processComp) {
        return super.save(processComp);
    }

    @InterceptorIgnore(tenantLine = "true")
    @Override
    public List<ProcessCompDTO> queryByCodes(List<String> compCodeList, List<String> orgList) {
        LambdaQueryWrapper<ProcessCompDO> wrapper = Wrappers.lambdaQuery();
        wrapper.in(ProcessCompDO::getCompCode, compCodeList);
        wrapper.in(ProcessCompDO::getOrgId, orgList);
        List<ProcessCompDO> list = baseMapper.selectList(wrapper);
        return BeanUtil.copyToList(list, ProcessCompDTO.class);
    }
}
